using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using SimpleServiceBus.Endpoint;
using SimpleServiceBus.Configuration;
using SimpleServiceBus.Endpoints.ActiveMQ.Transport;
using SimpleServiceBus.Bus.Transport;
using SimpleServiceBus.Bus.Pipeline;
using SimpleServiceBus.Bus.MessageManagement.Serialization;
using SimpleServiceBus.Bus;
using SimpleServiceBus.Bus.Pipeline.PipelineComponents.MessageLogging;

namespace SimpleServiceBus.Endpoints.ActiveMQ.Configuration {

    public class ActiveMQEndpointBuilder<EndpointType>: EndpointBuilder<EndpointType, ActiveMQTransport>
        where EndpointType: class, IMessagingEndpoint {

        //-----< Fields >-----
        //----------------------------------------------------------------------------------        


        //-----< Constructors >-----
        //----------------------------------------------------------------------------------        


        //-----< Public and protected properties >-----
        //----------------------------------------------------------------------------------        


        //-----< Public and protected methods >-----
        //----------------------------------------------------------------------------------        

        protected override void InitializeEndpoint() {
            RegisterService<IMessageSerializer, ActiveMQXmlMessageSerializer>(true);
            RegisterService<IMessageBus, ActiveMQMessageBus>(true);
            RegisterService<IMessagePipelineFactory, ActiveMQMessagePipelineFactory>(true);
            RegisterService<IMessageLogger, FakeMessageLogger>(true);
            base.InitializeEndpoint();
            var _transport = GetService<ITransport>() as ActiveMQTransport;
            if(_transport != null)
                RegisterService<IMessageProcessingErrorHandler>(_transport);
            RegisterService<IDestinationResolver>(new DefaultDestinationResolver());
        }

        //-----< Events >-----
        //----------------------------------------------------------------------------------        


        //-----< Internal members >-----
        //----------------------------------------------------------------------------------        


        //-----< Private members >-----
        //----------------------------------------------------------------------------------        


        //-----< All nested types >-----
        //----------------------------------------------------------------------------------        

        private class FakeMessageLogger: IMessageLogger {
            #region IMessageLogger Members

            public void LogMessage(IMessageContext messageContext, SimpleServiceBus.Endpoint.Metadata.MessageLoggingLevel logLevel) {
                // do nothing!
            }

            #endregion
        }

        //-----< All explicit interface implementations >-----
        //----------------------------------------------------------------------------------        


    }
}

